<template>
  <div class="error-page">
    <!-- 动态背景容器 -->
    <div class="particle-background">
      <div
        v-for="(particle, index) in particles"
        :key="index"
        class="particle"
        :style="particle.style"
      ></div>
    </div>

    <!-- 主要内容 -->
    <div class="error-content">
      <!-- 动态错误图标 -->
      <div class="error-icon">
        <div class="broken-chain"></div>
        <div class="warning-signal"></div>
      </div>

      <!-- 状态码 -->
      <h1 class="error-code glitch">404</h1>

      <!-- 错误描述 -->
      <p class="error-message">
        <span class="highlight">糟糕!</span> 您访问的页面
        <em class="text-stroke">失联</em>了...
      </p>

      <!-- 操作按钮组 -->
      <div class="action-buttons">
        <el-button
          class="back-btn"
          @click="$router.go(-1)"
        >
          <i class="el-icon-back"></i>
          返回上一页
        </el-button>
        <el-button
          type="primary"
          class="home-btn"
          @click="$router.push({ name: 'home' })"
        >
          <i class="el-icon-s-home"></i>
          返回首页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 粒子动画逻辑
const particles = ref([])
const createParticles = () => {
  const count = 30
  particles.value = Array.from({ length: count }, (_, i) => ({
    style: {
      left: `${Math.random() * 100}%`,
      top: `${Math.random() * 100}%`,
      animationDelay: `${Math.random() * 2}s`,
      background: `hsl(${Math.random() * 360}, 70%, 60%)`
    }
  }))
}

onMounted(() => {
  createParticles()
})
</script>

<style lang="scss" scoped>
.error-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  overflow: hidden;
  position: relative;
}

.particle-background {
  position: absolute;
  width: 100%;
  height: 100%;

  .particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: float 6s infinite ease-in-out;
    opacity: 0.3;
  }
}

.error-content {
  text-align: center;
  z-index: 1;
  padding: 2rem;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 1.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transform: translateY(0);
  animation: contentEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.error-icon {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 2rem;

  .broken-chain {
    position: absolute;
    width: 100%;
    height: 100%;
    background: url('data:image/svg+xml;utf8,<svg ...></svg>');
    animation: chainBreak 1.2s ease-out;
  }

  .warning-signal {
    /* 自定义警示图标动画 */
  }
}

.error-code {
  font-size: 8rem;
  margin: 0 0 1rem;
  background: linear-gradient(45deg, #ff6b6b, #ff8e53);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 2px 2px 4px rgba(255, 107, 107, 0.2);
  animation: glitchAnim 2s infinite;
}

.error-message {
  font-size: 1.5rem;
  color: #495057;
  margin-bottom: 2rem;

  .highlight {
    color: #ff6b6b;
    font-weight: 600;
  }

  .text-stroke {
    color: transparent;
    -webkit-text-stroke: 1px #ff6b6b;
    text-shadow: 2px 2px 4px rgba(255, 107, 107, 0.2);
  }
}

.action-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;

  .el-button {
    transition: all 0.3s ease;
    padding: 0.8rem 1.5rem;
    border-radius: 0.8rem;
    font-weight: 500;

    i {
      margin-right: 0.5rem;
    }
  }

  .back-btn {
    background: rgba(255, 107, 107, 0.1);
    border: 2px solid #ff6b6b;
    color: #ff6b6b;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
    }
  }

  .home-btn {
    background: linear-gradient(45deg, #4ecdc4, #45b7af);
    border: none;
    color: white;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(78, 205, 196, 0.3);
    }
  }
}

/* 动画定义 */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

@keyframes glitchAnim {
  2% { text-shadow: 2px 0 #4ecdc4, -2px 0 #ff6b6b; }
  4% { text-shadow: 2px 0 #4ecdc4, -2px 0 #ff6b6b; }
  96% { text-shadow: none; }
}

@keyframes contentEntrance {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}
</style>
